package com.ict.txmsv2.controller.studentinfo;


import com.ict.txmsv2.dto.StudentInfoQueryDto;
import com.ict.txmsv2.model.Achievement;
import com.ict.txmsv2.model.RespBean;
import com.ict.txmsv2.model.RespPageBean;
import com.ict.txmsv2.services.IAchievementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;

/**
 * <p>
 * 就业考研情况 前端控制器
 * </p>
 *
 * @author lht
 * @since 2021-04-24
 */
@RestController
@RequestMapping("/achievement")
@Api(tags = "就业考研情况")
public class AchievementController {

    @Resource
    private IAchievementService achievementService;

    @GetMapping
    @ApiOperation(value = "分页模糊查询学生就业考研情况")
    public RespPageBean getCertificates(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer size,
                                        StudentInfoQueryDto queryDto) {
        return achievementService.list(page, size, queryDto);
    }

    @PostMapping
    @ApiOperation(value = "添加一个学生就业考研情况")
    public RespBean addCertificate(@RequestBody Achievement achievement) {
        if (achievementService.save(achievement)) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败！");
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除一份学生就业考研情况")
    public RespBean delCertificate(@PathVariable(value = "id") Integer id) {
        if (achievementService.removeById(id)) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败！");
    }

    @PutMapping
    @ApiOperation(value = "更新一个学生就业考研情况")
    public RespBean updateCertificate(@RequestBody Achievement achievement) {
        if (achievementService.updateById(achievement)) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败！");
    }

}
